#Boa:Frame:Frame1

import wx
import wx.richtext
import consultasBD
import utiles
from decimal import Decimal

def create(parent):
    return Frame1(parent)

[wxID_FRAME1, wxID_FRAME1BUTTON1, wxID_FRAME1BUTTON2, wxID_FRAME1BUTTON4, 
 wxID_FRAME1CHECKBOX1, wxID_FRAME1CHOICE1, wxID_FRAME1CHOICE2, 
 wxID_FRAME1CHOICE3, wxID_FRAME1CHOICE4, wxID_FRAME1COMBOBOX1, 
 wxID_FRAME1LISTBOX1, wxID_FRAME1PANEL1, wxID_FRAME1RADIOBUTTON1, 
 wxID_FRAME1RADIOBUTTON2, wxID_FRAME1RICHTEXTCTRL1, wxID_FRAME1STATICTEXT1, 
 wxID_FRAME1STATICTEXT10, wxID_FRAME1STATICTEXT11, wxID_FRAME1STATICTEXT12, 
 wxID_FRAME1STATICTEXT13, wxID_FRAME1STATICTEXT14, wxID_FRAME1STATICTEXT15, 
 wxID_FRAME1STATICTEXT16, wxID_FRAME1STATICTEXT17, wxID_FRAME1STATICTEXT18, 
 wxID_FRAME1STATICTEXT19, wxID_FRAME1STATICTEXT2, wxID_FRAME1STATICTEXT3, 
 wxID_FRAME1STATICTEXT4, wxID_FRAME1STATICTEXT5, wxID_FRAME1STATICTEXT6, 
 wxID_FRAME1STATICTEXT7, wxID_FRAME1STATICTEXT8, wxID_FRAME1STATICTEXT9, 
 wxID_FRAME1TEXTCTRL1, wxID_FRAME1TEXTCTRL10, wxID_FRAME1TEXTCTRL11, 
 wxID_FRAME1TEXTCTRL12, wxID_FRAME1TEXTCTRL2, wxID_FRAME1TEXTCTRL3, 
 wxID_FRAME1TEXTCTRL4, wxID_FRAME1TEXTCTRL5, wxID_FRAME1TEXTCTRL6, 
 wxID_FRAME1TEXTCTRL7, wxID_FRAME1TEXTCTRL8, wxID_FRAME1TEXTCTRL9, 
] = [wx.NewId() for _init_ctrls in range(46)]

class Frame1(wx.Frame):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
              pos=wx.Point(372, 30), size=wx.Size(588, 543),
              style=wx.DEFAULT_FRAME_STYLE, title='Alta de Cliente')
        self.SetClientSize(wx.Size(580, 516))

        self.panel1 = wx.Panel(id=wxID_FRAME1PANEL1, name='panel1', parent=self,
              pos=wx.Point(0, 0), size=wx.Size(580, 516),
              style=wx.TAB_TRAVERSAL)

        self.staticText1 = wx.StaticText(id=wxID_FRAME1STATICTEXT1,
              label='Nro. Cliente', name='staticText1', parent=self.panel1,
              pos=wx.Point(16, 8), size=wx.Size(57, 13), style=0)

        self.textCtrl1 = wx.TextCtrl(id=wxID_FRAME1TEXTCTRL1, name='textCtrl1',
              parent=self.panel1, pos=wx.Point(16, 24), size=wx.Size(80, 21),
              style=0, value='')
        self.textCtrl1.SetMaxLength(15)
        self.textCtrl1.SetEditable(False)
        self.textCtrl1.Enable(False)

        self.staticText2 = wx.StaticText(id=wxID_FRAME1STATICTEXT2,
              label='Nombre', name='staticText2', parent=self.panel1,
              pos=wx.Point(96, 8), size=wx.Size(37, 13), style=0)

        self.textCtrl2 = wx.TextCtrl(id=wxID_FRAME1TEXTCTRL2, name='textCtrl2',
              parent=self.panel1, pos=wx.Point(96, 24), size=wx.Size(328, 21),
              style=0, value='')
        self.textCtrl2.SetEditable(False)
        self.textCtrl2.SetMaxLength(50)
        self.textCtrl2.Enable(False)
        self.textCtrl2.Bind(wx.EVT_KILL_FOCUS, self.OnKillNombre)

        self.staticText3 = wx.StaticText(id=wxID_FRAME1STATICTEXT3,
              label='Tipo Documento', name='staticText3', parent=self.panel1,
              pos=wx.Point(96, 48), size=wx.Size(77, 13), style=0)

        self.choice1 = wx.Choice(choices=["DNI", "LC", "CI", "CUIL", "CUIT",
              "Pasaporte", "LE"], id=wxID_FRAME1CHOICE1, name='choice1',
              parent=self.panel1, pos=wx.Point(96, 64), size=wx.Size(104, 21),
              style=0)
        self.choice1.Enable(False)

        self.staticText4 = wx.StaticText(id=wxID_FRAME1STATICTEXT4,
              label='Numero Documento', name='staticText4', parent=self.panel1,
              pos=wx.Point(200, 48), size=wx.Size(94, 13), style=0)

        self.textCtrl3 = wx.TextCtrl(id=wxID_FRAME1TEXTCTRL3, name='textCtrl3',
              parent=self.panel1, pos=wx.Point(200, 64), size=wx.Size(112, 21),
              style=0, value='')
        self.textCtrl3.SetEditable(False)
        self.textCtrl3.SetMaxLength(16)
        self.textCtrl3.Enable(False)

        self.staticText5 = wx.StaticText(id=wxID_FRAME1STATICTEXT5,
              label='Situacion Fiscal', name='staticText5', parent=self.panel1,
              pos=wx.Point(320, 48), size=wx.Size(72, 13), style=0)

        self.choice2 = wx.Choice(choices=['Inscripto', 'Cons. Final',
              'Monotributo'], id=wxID_FRAME1CHOICE2, name='choice2',
              parent=self.panel1, pos=wx.Point(320, 64), size=wx.Size(104, 21),
              style=0)
        self.choice2.Enable(False)

        self.staticText6 = wx.StaticText(id=wxID_FRAME1STATICTEXT6,
              label='Direccion', name='staticText6', parent=self.panel1,
              pos=wx.Point(96, 88), size=wx.Size(43, 13), style=0)

        self.textCtrl4 = wx.TextCtrl(id=wxID_FRAME1TEXTCTRL4, name='textCtrl4',
              parent=self.panel1, pos=wx.Point(96, 104), size=wx.Size(328, 21),
              style=0, value='')
        self.textCtrl4.SetMaxLength(50)
        self.textCtrl4.SetEditable(False)
        self.textCtrl4.Enable(False)

        self.staticText7 = wx.StaticText(id=wxID_FRAME1STATICTEXT7,
              label='Localidad', name='staticText7', parent=self.panel1,
              pos=wx.Point(96, 168), size=wx.Size(44, 13), style=0)

        self.staticText8 = wx.StaticText(id=wxID_FRAME1STATICTEXT8,
              label='Provincia', name='staticText8', parent=self.panel1,
              pos=wx.Point(183, 128), size=wx.Size(43, 13), style=0)

        self.staticText9 = wx.StaticText(id=wxID_FRAME1STATICTEXT9,
              label='Pais', name='staticText9', parent=self.panel1,
              pos=wx.Point(96, 128), size=wx.Size(19, 13), style=0)

        self.choice3 = wx.Choice(choices=["Argentina", "Uruguay", "Brasil",
              "Chile", "Paraguay", "Peru", "otro"], id=wxID_FRAME1CHOICE3,
              name='choice3', parent=self.panel1, pos=wx.Point(96, 144),
              size=wx.Size(80, 21), style=0)
        self.choice3.Enable(False)
        self.choice3.Bind(wx.EVT_CHOICE, self.OnElijePais,
              id=wxID_FRAME1CHOICE3)

        self.choice4 = wx.Choice(choices=["SANTA FE", "ENTRE RIOS",
              "CORRIENTES", "BUENOS AIRES", "MISIONES",
              "CIUDAD DE BUENOS AIRES", "CORDOBA", "CHACO", "FORMOSA",
              "SANTIAGO DEL ESTERO", "TUCUMAN", "SALTA", "JUJUY", "CATAMARCA",
              "LA RIOJA", "SAN JUAN", "MENDOZA", "SAN LUIS", "LA PAMPA",
              "NEUQUEN", "RIO NEGRO", "CHUBUT", "SANTA CRUZ",
              "TIERRA DEL FUEGO", "sin especificar"], id=wxID_FRAME1CHOICE4,
              name='choice4', parent=self.panel1, pos=wx.Point(180, 144),
              size=wx.Size(148, 21), style=0)
        self.choice4.Enable(False)

        self.comboBox1 = wx.ComboBox(choices=[], id=wxID_FRAME1COMBOBOX1,
              name='comboBox1', parent=self.panel1, pos=wx.Point(96, 184),
              size=wx.Size(232, 21), style=0, value='')
        self.comboBox1.SetLabel('')
        self.comboBox1.Enable(False)
        self.comboBox1.Bind(wx.EVT_TEXT, self.OnTextoIngresado,
              id=wxID_FRAME1COMBOBOX1)
        self.comboBox1.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)

        self.listBox1 = wx.ListBox(choices=[], id=wxID_FRAME1LISTBOX1,
              name='listBox1', parent=self.panel1, pos=wx.Point(96, 208),
              size=wx.Size(216, 72), style=0)
        self.listBox1.Enable(False)
        self.listBox1.SetBackgroundColour(wx.Colour(212, 208, 200))
        self.listBox1.Bind(wx.EVT_LISTBOX, self.OnListBox,
              id=wxID_FRAME1LISTBOX1)

        self.staticText10 = wx.StaticText(id=wxID_FRAME1STATICTEXT10,
              label='Codigo Postal', name='staticText10', parent=self.panel1,
              pos=wx.Point(96, 288), size=wx.Size(65, 13), style=0)

        self.textCtrl6 = wx.TextCtrl(id=wxID_FRAME1TEXTCTRL6, name='textCtrl6',
              parent=self.panel1, pos=wx.Point(96, 304), size=wx.Size(64, 21),
              style=0, value='')
        self.textCtrl6.SetEditable(False)
        self.textCtrl6.SetMaxLength(8)
        self.textCtrl6.Enable(False)

        self.staticText11 = wx.StaticText(id=wxID_FRAME1STATICTEXT11,
              label='Telefono', name='staticText11', parent=self.panel1,
              pos=wx.Point(336, 168), size=wx.Size(42, 13), style=0)

        self.textCtrl7 = wx.TextCtrl(id=wxID_FRAME1TEXTCTRL7, name='textCtrl7',
              parent=self.panel1, pos=wx.Point(336, 184), size=wx.Size(232, 21),
              style=0, value='')
        self.textCtrl7.SetEditable(False)
        self.textCtrl7.SetMaxLength(40)
        self.textCtrl7.Enable(False)

        self.staticText12 = wx.StaticText(id=wxID_FRAME1STATICTEXT12,
              label='e-mail', name='staticText12', parent=self.panel1,
              pos=wx.Point(336, 208), size=wx.Size(28, 13), style=0)

        self.textCtrl8 = wx.TextCtrl(id=wxID_FRAME1TEXTCTRL8, name='textCtrl8',
              parent=self.panel1, pos=wx.Point(336, 224), size=wx.Size(232, 21),
              style=0, value='')
        self.textCtrl8.SetEditable(False)
        self.textCtrl8.SetMaxLength(50)
        self.textCtrl8.Enable(False)

        self.checkBox1 = wx.CheckBox(id=wxID_FRAME1CHECKBOX1,
              label='Lista negra', name='checkBox1', parent=self.panel1,
              pos=wx.Point(496, 248), size=wx.Size(70, 13), style=0)
        self.checkBox1.SetValue(False)
        self.checkBox1.Enable(False)

        self.staticText13 = wx.StaticText(id=wxID_FRAME1STATICTEXT13,
              label='Cumple', name='staticText13', parent=self.panel1,
              pos=wx.Point(336, 248), size=wx.Size(35, 13), style=0)

        self.textCtrl9 = wx.TextCtrl(id=wxID_FRAME1TEXTCTRL9, name='textCtrl9',
              parent=self.panel1, pos=wx.Point(336, 264), size=wx.Size(24, 21),
              style=0, value='00')
        self.textCtrl9.SetMaxLength(2)
        self.textCtrl9.SetEditable(False)
        self.textCtrl9.Enable(False)

        self.textCtrl10 = wx.TextCtrl(id=wxID_FRAME1TEXTCTRL10,
              name='textCtrl10', parent=self.panel1, pos=wx.Point(360, 264),
              size=wx.Size(24, 21), style=0, value='00')
        self.textCtrl10.SetMaxLength(2)
        self.textCtrl10.SetEditable(False)
        self.textCtrl10.Enable(False)

        self.textCtrl5 = wx.TextCtrl(id=wxID_FRAME1TEXTCTRL5, name='textCtrl5',
              parent=self.panel1, pos=wx.Point(336, 304), size=wx.Size(88, 21),
              style=0, value='')
        self.textCtrl5.SetEditable(False)
        self.textCtrl5.Enable(False)
        self.textCtrl5.SetMaxLength(10)

        self.staticText14 = wx.StaticText(id=wxID_FRAME1STATICTEXT14,
              label='(dia / mes)', name='staticText14', parent=self.panel1,
              pos=wx.Point(392, 264), size=wx.Size(51, 13), style=0)

        self.staticText15 = wx.StaticText(id=wxID_FRAME1STATICTEXT15,
              label='Observaciones', name='staticText15', parent=self.panel1,
              pos=wx.Point(96, 328), size=wx.Size(71, 13), style=0)

        self.richTextCtrl1 = wx.richtext.RichTextCtrl(id=wxID_FRAME1RICHTEXTCTRL1,
              parent=self.panel1, pos=wx.Point(96, 344), size=wx.Size(472, 64),
              style=wx.richtext.RE_MULTILINE, value='')
        self.richTextCtrl1.SetLabel('text')
        self.richTextCtrl1.SetEditable(False)
        self.richTextCtrl1.Enable(False)
        self.richTextCtrl1.SetBackgroundColour(wx.Colour(212, 208, 200))

        self.textCtrl12 = wx.TextCtrl(id=wxID_FRAME1TEXTCTRL12,
              name='textCtrl12', parent=self.panel1, pos=wx.Point(336, 432),
              size=wx.Size(88, 21), style=0, value='')
        self.textCtrl12.Enable(False)
        self.textCtrl12.SetEditable(False)

        self.staticText16 = wx.StaticText(id=wxID_FRAME1STATICTEXT16,
              label='Resumen Cuenta Corriente', name='staticText16',
              parent=self.panel1, pos=wx.Point(96, 416), size=wx.Size(130, 13),
              style=0)

        self.radioButton1 = wx.RadioButton(id=wxID_FRAME1RADIOBUTTON1,
              label='SI, recibir resumen', name='radioButton1',
              parent=self.panel1, pos=wx.Point(96, 432), size=wx.Size(120, 13),
              style=0)
        self.radioButton1.SetValue(False)
        self.radioButton1.Enable(False)

        self.radioButton2 = wx.RadioButton(id=wxID_FRAME1RADIOBUTTON2,
              label='NO, recibir resumen', name='radioButton2',
              parent=self.panel1, pos=wx.Point(96, 448), size=wx.Size(112, 13),
              style=0)
        self.radioButton2.SetValue(False)
        self.radioButton2.Enable(False)

        self.staticText17 = wx.StaticText(id=wxID_FRAME1STATICTEXT17,
              label='Direccion del resumen', name='staticText17',
              parent=self.panel1, pos=wx.Point(96, 464), size=wx.Size(104, 13),
              style=0)

        self.textCtrl11 = wx.TextCtrl(id=wxID_FRAME1TEXTCTRL11,
              name='textCtrl11', parent=self.panel1, pos=wx.Point(96, 480),
              size=wx.Size(320, 21), style=0, value='@')
        self.textCtrl11.Enable(False)
        self.textCtrl11.SetEditable(False)
        self.textCtrl11.SetMaxLength(50)

        self.button1 = wx.Button(id=wxID_FRAME1BUTTON1, label='ALTAS',
              name='button1', parent=self.panel1, pos=wx.Point(493, 24),
              size=wx.Size(75, 23), style=0)

        self.button2 = wx.Button(id=wxID_FRAME1BUTTON2, label='Limpiar',
              name='button2', parent=self.panel1, pos=wx.Point(488, 448),
              size=wx.Size(75, 23), style=0)
        self.button2.Bind(wx.EVT_BUTTON, self.OnLimpiar, id=wxID_FRAME1BUTTON2)

        self.button4 = wx.Button(id=wxID_FRAME1BUTTON4, label='Salir',
              name='button4', parent=self.panel1, pos=wx.Point(488, 480),
              size=wx.Size(75, 23), style=0)
        self.button4.Bind(wx.EVT_BUTTON, self.OnSalir, id=wxID_FRAME1BUTTON4)

        self.staticText18 = wx.StaticText(id=wxID_FRAME1STATICTEXT18,
              label='Fecha alta', name='staticText18', parent=self.panel1,
              pos=wx.Point(336, 288), size=wx.Size(50, 13), style=0)

        self.staticText19 = wx.StaticText(id=wxID_FRAME1STATICTEXT19,
              label='Puntaje', name='staticText19', parent=self.panel1,
              pos=wx.Point(336, 416), size=wx.Size(37, 13), style=0)

    def __init__(self, parent):
        self._init_ctrls(parent)
        self.inicializar()
        self.habilitarAlta()
        self.parametrosAlta()

    def inicializar(self):
        sql = "SELECT DISTINCT localidad FROM cliente WHERE 1 ORDER BY localidad"
        resultado = consultasBD.ordenCrudaDict(sql)
        for item in resultado:
            self.comboBox1.Append(item["localidad"])
        
    def parametrosAlta(self):
        self.choice1.SetSelection(0)
        self.choice2.SetSelection(1)
        self.choice3.SetSelection(0)
        sucursal = utiles.getSucursalActiva()
        if sucursal == "2":
            self.choice4.SetSelection(1)
        else:
            self.choice4.SetSelection(0)

    def OnElijePais(self, event):
        if self.choice3.GetSelection()<>0:
            posicion = len(self.choice4.GetItems())
            self.choice4.SetSelection(24)
            self.comboBox1.SetLabel("sin especificar")
        else:
            self.choice4.SetSelection(0)
            self.comboBox1.SetLabel("")

    def OnTextoIngresado(self, event):
        texto = self.comboBox1.GetLabel().upper()
        self.listBox1.Clear()
        for item in self.comboBox1.GetItems():
            if texto in item:
                self.listBox1.Append(item)

    def OnKillFocus(self, event):
        localidad = self.comboBox1.GetLabel().upper()
        self.comboBox1.SetLabel(localidad)

    def OnListBox(self, event):
        seleccion = self.listBox1.GetSelection()
        self.comboBox1.SetLabel(self.listBox1.GetItems()[seleccion])
        self.comboBox1.SetFocus()

    def OnLimpiar(self, event):
        self.textCtrl1.SetLabel("")
        self.textCtrl2.SetLabel("")
        self.textCtrl3.SetLabel("")
        self.textCtrl4.SetLabel("")
        self.textCtrl5.SetLabel("")
        self.textCtrl6.SetLabel("")
        self.textCtrl7.SetLabel("")
        self.textCtrl8.SetLabel("")
        self.textCtrl9.SetLabel("00")
        self.textCtrl10.SetLabel("00")
        self.textCtrl11.SetLabel("@")
        self.comboBox1.SetLabel("")
        self.richTextCtrl1.SetValue("")
        self.radioButton1.SetValue(False)
        self.radioButton2.SetValue(False)
        self.checkBox1.SetValue(False)
        self.choice1.SetSelection(0)
        self.choice2.SetSelection(1)
        self.choice3.SetSelection(-1)
        self.choice4.SetSelection(-1)
        self.parametrosAlta()
        self.textCtrl2.SetFocus()

    def OnSalir(self, event):
        self.Close()
        
    def habilitarAlta(self):
        self.textCtrl1.Enable(True) # codigo de cliente
        self.textCtrl1.SetEditable(False) #el codigo se asigna automaticamente
        self.textCtrl2.Enable(True) # nombre
        self.textCtrl2.SetEditable(True)
        self.choice1.Enable(True) # tipo documento
        self.choice1.SetSelection(0)
        self.textCtrl3.Enable(True) #numero documento
        self.textCtrl3.SetEditable(True)
        self.choice2.Enable(True) # situacion fiscal
        self.choice2.SetSelection(1)
        self.textCtrl4.Enable(True) # direccion
        self.textCtrl4.SetEditable(True)
        self.choice3.Enable(True) # pais
        self.choice3.SetSelection(0)
        self.choice4.Enable(True) # provincia
        self.choice4.SetSelection(0)
        self.comboBox1.Enable(True) # localidad
        self.comboBox1.SetEditable(True)
        self.listBox1.SetBackgroundColour(wx.Colour(255, 255, 255))
        self.listBox1.Refresh()
        self.textCtrl6.Enable(True) # CP
        self.textCtrl6.SetEditable(True)
        self.textCtrl7.Enable(True) # telefono
        self.textCtrl7.SetEditable(True)
        self.textCtrl8.Enable(True) # email
        self.textCtrl8.SetEditable(True)
        self.textCtrl9.Enable(True) # cumple: dia
        self.textCtrl9.SetEditable(True)
        self.textCtrl10.Enable(True) # cumple: mes
        self.textCtrl10.SetEditable(True)
        self.textCtrl11.Enable(True) # direcion envio resumen
        self.textCtrl11.SetEditable(True)
        self.richTextCtrl1.Enable(True) # observaciones
        self.richTextCtrl1.SetEditable(True)
        self.richTextCtrl1.SetBackgroundColour(wx.Colour(255, 255, 255))
        self.richTextCtrl1.Refresh()
        self.radioButton1.Enable(True) # SI, envio resumen
        self.radioButton2.Enable(True) # NO, envio resumen
        self.checkBox1.Enable(True)
        self.button1.SetLabel("GUARDAR")
        self.textCtrl2.SetFocus() # nombre cliente

    def OnKillNombre(self, event):
        if self.textCtrl2.GetLabel()=="":
            return
        listaNombre = (self.textCtrl2.GetLabel()).split()
        r1 = "SELECT * FROM cliente WHERE 1 AND (\n"
        for item in listaNombre:
            r1+= "nombre LIKE '%"+item+"%' OR \n"
        r1 = r1[:-5]
        r1+= ")\n"
        sql = r1
        resultados = consultasBD.ordenCruda(sql)
        if resultados == () or len(resultados)==0 or resultados==None:
            return
    
        import ClienteAltaVerificar
        clienteVerificar = ClienteAltaVerificar.create(None, resultados)
        try:
            clienteVerificar.ShowModal()
            #Fecha,NroDocumento,id,Tipo,CostoUnidad
            repuesta = clienteVerificar.getRepuesta()
        finally:
            clienteVerificar.Destroy()

        print repuesta
        

